home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / elib-006.lha / elib-0.06 / library / elib-node.el < prev    next >
Text File  |  1993-01-24  |  3KB  |  100 lines

  1. ;;;; $Id: elib-node.el,v 0.5 1992/08/19 01:57:39 ceder Exp $
  2. ;;;; This file implements the nodes used in binary trees and
  3. ;;;; doubly linked lists
  4. ;;;;
  5. ;;;; Copyright (C) 1991, 1992 Free Software Foundation
  6. ;;;;
  7. ;;;; This file is part of the GNU Emacs lisp library, Elib.
  8. ;;;;
  9. ;;;; GNU Elib is free software; you can redistribute it and/or modify
  10. ;;;; it under the terms of the GNU General Public License as published by
  11. ;;;; the Free Software Foundation; either version 1, or (at your option)
  12. ;;;; any later version.
  13. ;;;;
  14. ;;;; GNU Elib is distributed in the hope that it will be useful,
  15. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. ;;;; GNU General Public License for more details.
  18. ;;;;
  19. ;;;; You should have received a copy of the GNU General Public License
  20. ;;;; along with GNU Emacs; see the file COPYING.  If not, write to
  21. ;;;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22. ;;;; 
  23. ;;;; Author: Inge Wallin
  24. ;;;; 
  25.  
  26. ;;;
  27. ;;; A node is implemented as an array with three elements, using
  28. ;;; (elt node 0) as the left pointer
  29. ;;; (elt node 1) as the right pointer
  30. ;;; (elt node 2) as the data
  31. ;;;
  32. ;;; Some types of trees, e.g. AVL trees, need bigger nodes, but 
  33. ;;; as long as the first three parts are the left pointer, the 
  34. ;;; right pointer and the data field, these macros can be used.
  35. ;;;
  36.  
  37.  
  38. (provide 'elib-node)
  39.  
  40.  
  41. (defmacro elib-node-create (left right data)
  42.  
  43.   ;; Create a tree node from LEFT, RIGHT and DATA.
  44.   (` (vector (, left) (, right) (, data))))
  45.  
  46.  
  47. (defmacro elib-node-left (node)
  48.  
  49.   ;; Return the left pointer of NODE.
  50.   (` (aref (, node) 0)))
  51.  
  52.  
  53. (defmacro elib-node-right (node)
  54.  
  55.   ;; Return the right pointer of NODE.
  56.   (` (aref (, node) 1)))
  57.  
  58.  
  59. (defmacro elib-node-data (node)
  60.  
  61.   ;; Return the data of NODE.
  62.   (` (aref (, node) 2)))
  63.  
  64.  
  65. (defmacro elib-node-set-left (node newleft)
  66.  
  67.   ;; Set the left pointer of NODE to NEWLEFT.
  68.   (` (aset (, node) 0 (, newleft))))
  69.  
  70.  
  71. (defmacro elib-node-set-right (node newright)
  72.  
  73.   ;; Set the right pointer of NODE to NEWRIGHT.
  74.   (` (aset (, node) 1 (, newright))))
  75.  
  76.  
  77. (defmacro elib-node-set-data (node newdata)
  78.   ;; Set the data of NODE to NEWDATA.
  79.   (` (aset (, node) 2 (, newdata))))
  80.  
  81.  
  82.  
  83. (defmacro elib-node-branch (node branch)
  84.  
  85.   ;; Get value of a branch of a node.
  86.   ;; 
  87.   ;; NODE is the node, and BRANCH is the branch.
  88.   ;; 0 for left pointer, 1 for right pointer and 2 for the data."
  89.   (` (aref (, node) (, branch))))
  90.  
  91.  
  92. (defmacro elib-node-set-branch (node branch newval)
  93.  
  94.   ;; Set value of a branch of a node.
  95.   ;;
  96.   ;; NODE is the node, and BRANCH is the branch.
  97.   ;; 0 for left pointer, 1 for the right pointer and 2 for the data.
  98.   ;; NEWVAL is new value of the branch."
  99.   (` (aset (, node) (, branch) (, newval))))
  100.